import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'

// 设置 axios 默认配置
axios.defaults.timeout = 30000  // 设置为 30 秒
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'

// 添加请求拦截器
axios.interceptors.request.use(config => {
  console.log('Request:', config.method.toUpperCase(), config.url)
  return config
})

// 添加响应拦截器
axios.interceptors.response.use(
  response => {
    console.log('Response:', response.status, response.data)
    return response
  },
  error => {
    if (error.code === 'ECONNABORTED' && error.message.includes('timeout')) {
      ElMessage.error('请求超时，请重试')
    } else {
      ElMessage.error(error.response?.data?.message || '请求失败，请稍后重试')
    }
    console.error('Error:', error)
    return Promise.reject(error)
  }
)

const app = createApp(App)
app.use(ElementPlus)
app.use(router)
app.mount('#app')